package bookmanage;

import javax.swing.JPanel;
import javax.swing.JLabel;

import java.awt.Font;
import java.awt.Image;
import java.awt.Toolkit;

import javax.swing.ButtonGroup;
import javax.swing.ImageIcon;
import javax.swing.JFileChooser;
import javax.swing.JInternalFrame;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import javax.swing.JRadioButton;
import javax.swing.JComboBox;
import javax.swing.JButton;

import java.awt.Color;
import java.awt.event.ItemListener;
import java.awt.event.ItemEvent;

import javax.swing.border.LineBorder;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.text.SimpleDateFormat;
import javax.swing.event.InternalFrameAdapter;
import javax.swing.event.InternalFrameEvent;

public class MemberEditDel extends JInternalFrame {
	private JLabel label;
	private JLabel label_1;
	private JTextField userid;
	private JPasswordField userpwd1;
	private JLabel label_2;
	private JPasswordField userpwd2;
	private JLabel label_3;
	private JTextField username;
	private JLabel label_4;
	private JRadioButton radio1;
	private JRadioButton radio2;
	private JLabel label_5;
	private JComboBox birth_year;
	private JComboBox birth_month;
	private JComboBox birth_day;
	private JLabel label_6;
	private JTextField zipcode;
	private JButton button;
	private JLabel label_7;
	private JTextField addr1;
	private JTextField addr2;
	private JLabel label_8;
	private JTextField email1;
	private JLabel label_9;
	private JComboBox email2;
	private JLabel label_10;
	private JLabel label_11;
	private JLabel label_12;
	private JComboBox phone1;
	private JLabel label_13;
	private JTextField phone2;
	private JLabel label_14;
	private JTextField phone3;
	private JComboBox classname;
	private JComboBox grade;
	private JLabel sajin;
	private JButton button_2;
	private JButton button_1;
	private JButton button_3;
	private JButton button_4;

	Connection con;
	SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
	String fileName;
	BMMain m;
	/**
	 * Create the panel.
	 */
	public MemberEditDel(BMMain main) {
		super("회원 수정/삭제",true,true,false,true);
		this.m=main;
		addInternalFrameListener(new InternalFrameAdapter() {
			@Override
			public void internalFrameClosing(InternalFrameEvent e) {
				m.med=null;
			}
		});
		this.con=main.con;
		getContentPane().setLayout(null);
		getContentPane().add(getLabel());
		getContentPane().add(getLabel_1());
		getContentPane().add(getUserid());
		getContentPane().add(getUserpwd1());
		getContentPane().add(getLabel_2());
		getContentPane().add(getUserpwd2());
		getContentPane().add(getLabel_3());
		getContentPane().add(getUsername());
		getContentPane().add(getLabel_4());
		getContentPane().add(getRadio1());
		getContentPane().add(getRadio2());
		getContentPane().add(getLabel_5());
		getContentPane().add(getBirth_year());
		getContentPane().add(getBirth_month());
		getContentPane().add(getBirth_day());
		getContentPane().add(getLabel_6());
		getContentPane().add(getZipcode());
		getContentPane().add(getButton());
		getContentPane().add(getLabel_7());
		getContentPane().add(getAddr1());
		getContentPane().add(getAddr2());
		getContentPane().add(getLabel_8());
		getContentPane().add(getEmail1());
		getContentPane().add(getLabel_9());
		getContentPane().add(getEmail2());
		getContentPane().add(getLabel_10());
		getContentPane().add(getLabel_11());
		getContentPane().add(getLabel_12());
		getContentPane().add(getPhone1());
		getContentPane().add(getLabel_13());
		getContentPane().add(getPhone2());
		getContentPane().add(getLabel_14());
		getContentPane().add(getPhone3());
		getContentPane().add(getClassname());
		getContentPane().add(getGrade());
		ButtonGroup bg = new ButtonGroup();
		bg.add(radio1);
		bg.add(radio2);
		getContentPane().add(getSajin());
		getContentPane().add(getButton_2());
		getContentPane().add(getButton_1_1());
		getContentPane().add(getButton_3());
		getContentPane().add(getButton_4());
		for(int i=1;i<=31;i++){
			if(i<10) birth_day.addItem("0"+i+"일");
			else birth_day.addItem(i+"일");
		}
		setResizable(false);
	}

	private JLabel getLabel() {
		if (label == null) {
			label = new JLabel("아이디");
			label.setFont(new Font("굴림", Font.BOLD, 14));
			label.setBounds(12, 10, 70, 25);
		}
		return label;
	}
	private JLabel getLabel_1() {
		if (label_1 == null) {
			label_1 = new JLabel("비밀번호");
			label_1.setFont(new Font("굴림", Font.BOLD, 14));
			label_1.setBounds(12, 45, 70, 25);
		}
		return label_1;
	}
	private JTextField getUserid() {
		if (userid == null) {
			userid = new JTextField();
			userid.setEditable(false);
			userid.setColumns(10);
			userid.setBounds(88, 10, 125, 22);
		}
		return userid;
	}
	private JPasswordField getUserpwd1() {
		if (userpwd1 == null) {
			userpwd1 = new JPasswordField();
			userpwd1.setBounds(88, 45, 125, 22);
		}
		return userpwd1;
	}
	private JLabel getLabel_2() {
		if (label_2 == null) {
			label_2 = new JLabel("재확인");
			label_2.setFont(new Font("굴림", Font.BOLD, 14));
			label_2.setBounds(12, 80, 85, 25);
		}
		return label_2;
	}
	private JPasswordField getUserpwd2() {
		if (userpwd2 == null) {
			userpwd2 = new JPasswordField();
			userpwd2.setBounds(88, 80, 125, 22);
		}
		return userpwd2;
	}
	private JLabel getLabel_3() {
		if (label_3 == null) {
			label_3 = new JLabel("이 름");
			label_3.setFont(new Font("굴림", Font.BOLD, 14));
			label_3.setBounds(12, 115, 70, 25);
		}
		return label_3;
	}
	private JTextField getUsername() {
		if (username == null) {
			username = new JTextField();
			username.setColumns(10);
			username.setBounds(88, 115, 125, 22);
		}
		return username;
	}
	private JLabel getLabel_4() {
		if (label_4 == null) {
			label_4 = new JLabel("성 별");
			label_4.setFont(new Font("굴림", Font.BOLD, 14));
			label_4.setBounds(12, 150, 70, 25);
		}
		return label_4;
	}
	private JRadioButton getRadio1() {
		if (radio1 == null) {
			radio1 = new JRadioButton("여자");
			radio1.setBounds(88, 150, 60, 25);
		}
		return radio1;
	}
	private JRadioButton getRadio2() {
		if (radio2 == null) {
			radio2 = new JRadioButton("남자");
			radio2.setBounds(152, 150, 60, 25);
		}
		return radio2;
	}
	private JLabel getLabel_5() {
		if (label_5 == null) {
			label_5 = new JLabel("생 일");
			label_5.setFont(new Font("굴림", Font.BOLD, 14));
			label_5.setBounds(12, 185, 70, 25);
		}
		return label_5;
	}
	private JComboBox getBirth_year() {
		if (birth_year == null) {
			birth_year = new JComboBox();
			for(int i=2014;i>=1910;i--){
				birth_year.addItem(i+"년");
			}
			birth_year.addItemListener(new ItemListener() {
				public void itemStateChanged(ItemEvent e) {
					String yearS = (String)birth_year.getSelectedItem();
					String monthS = (String)birth_month.getSelectedItem();
					monthS = monthS.substring(0, 2);
					if(monthS.equals("01") || monthS.equals("03") || monthS.equals("05") || monthS.equals("07")
							|| monthS.equals("08") || monthS.equals("10") || monthS.equals("12")){
						for(int i=1;i<=31;i++){
							if(i<10) birth_day.addItem("0"+i+"일");
							else birth_day.addItem(i+"일");
						}
					}else if(monthS.equals("04") || monthS.equals("06") || monthS.equals("09") || monthS.equals("11")){
						for(int i=1;i<=30;i++){
							if(i<10) birth_day.addItem("0"+i+"일");
							else birth_day.addItem(i+"일");
						}
					}else{
						int yearI = Integer.parseInt(yearS.substring(0, 4));
						if(yearI%4==0){
							for(int i=1;i<=29;i++){
								if(i<10) birth_day.addItem("0"+i+"일");
								else birth_day.addItem(i+"일");
							}
						}else{
							for(int i=1;i<=28;i++){
								if(i<10) birth_day.addItem("0"+i+"일");
								else birth_day.addItem(i+"일");
							}
						}
					}
				}
			});
			birth_year.setBounds(88, 185, 125, 25);
		}
		return birth_year;
	}
	private JComboBox getBirth_month() {
		if (birth_month == null) {
			birth_month = new JComboBox();
			for(int i=1;i<=12;i++){
				if(i<10) birth_month.addItem("0"+i+"월");
				else birth_month.addItem(i+"월");
			}
			birth_month.addItemListener(new ItemListener() {
				public void itemStateChanged(ItemEvent e) {
					String yearS = (String)birth_year.getSelectedItem();
					String monthS = (String)birth_month.getSelectedItem();
					monthS = monthS.substring(0, 2);
					if(monthS.equals("01") || monthS.equals("03") || monthS.equals("05") || monthS.equals("07")
							|| monthS.equals("08") || monthS.equals("10") || monthS.equals("12")){
						for(int i=1;i<=31;i++){
							if(i<10) birth_day.addItem("0"+i+"일");
							else birth_day.addItem(i+"일");
						}
					}else if(monthS.equals("04") || monthS.equals("06") || monthS.equals("09") || monthS.equals("11")){
						for(int i=1;i<=30;i++){
							if(i<10) birth_day.addItem("0"+i+"일");
							else birth_day.addItem(i+"일");
						}
					}else{
						int yearI = Integer.parseInt(yearS.substring(0, 4));
						if(yearI%4==0){
							for(int i=1;i<=29;i++){
								if(i<10) birth_day.addItem("0"+i+"일");
								else birth_day.addItem(i+"일");
							}
						}else{
							for(int i=1;i<=28;i++){
								if(i<10) birth_day.addItem("0"+i+"일");
								else birth_day.addItem(i+"일");
							}
						}
					}
				}
			});
			birth_month.setBounds(225, 185, 70, 25);
		}
		return birth_month;
	}
	private JComboBox getBirth_day() {
		if (birth_day == null) {
			birth_day = new JComboBox();
			birth_day.setBounds(307, 185, 70, 25);
		}
		return birth_day;
	}
	private JLabel getLabel_6() {
		if (label_6 == null) {
			label_6 = new JLabel("우편번호");
			label_6.setFont(new Font("굴림", Font.BOLD, 14));
			label_6.setBounds(12, 220, 70, 25);
		}
		return label_6;
	}
	private JTextField getZipcode() {
		if (zipcode == null) {
			zipcode = new JTextField();
			zipcode.setEditable(false);
			zipcode.setColumns(10);
			zipcode.setBounds(88, 220, 125, 22);
		}
		return zipcode;
	}
	private JButton getButton() {
		if (button == null) {
			button = new JButton("검색");
			button.setBounds(234, 220, 97, 23);
		}
		return button;
	}
	private JLabel getLabel_7() {
		if (label_7 == null) {
			label_7 = new JLabel("주소");
			label_7.setFont(new Font("굴림", Font.BOLD, 14));
			label_7.setBounds(12, 255, 70, 25);
		}
		return label_7;
	}
	private JTextField getAddr1() {
		if (addr1 == null) {
			addr1 = new JTextField();
			addr1.setEditable(false);
			addr1.setColumns(10);
			addr1.setBounds(88, 255, 243, 22);
		}
		return addr1;
	}
	private JTextField getAddr2() {
		if (addr2 == null) {
			addr2 = new JTextField();
			addr2.setColumns(10);
			addr2.setBounds(88, 290, 243, 22);
		}
		return addr2;
	}
	private JLabel getLabel_8() {
		if (label_8 == null) {
			label_8 = new JLabel("이메일");
			label_8.setFont(new Font("굴림", Font.BOLD, 14));
			label_8.setBounds(12, 325, 70, 25);
		}
		return label_8;
	}
	private JTextField getEmail1() {
		if (email1 == null) {
			email1 = new JTextField();
			email1.setColumns(10);
			email1.setBounds(88, 325, 125, 22);
		}
		return email1;
	}
	private JLabel getLabel_9() {
		if (label_9 == null) {
			label_9 = new JLabel("@");
			label_9.setBounds(219, 325, 19, 22);
		}
		return label_9;
	}
	private JComboBox getEmail2() {
		if (email2 == null) {
			email2 = new JComboBox();
			email2.setOpaque(false);
			email2.setBackground(Color.WHITE);
			email2.setBounds(240, 325, 140, 22);
			email2.addItem("nate.com");
			email2.addItem("cyworld.com");
			email2.addItem("empas.com");
			email2.addItem("lycos.co.kr");
			email2.addItem("netsgo.com");
			email2.addItem("hanmail.net");
			email2.addItem("naver.com");
			email2.addItem("yachoo.co.kr");
			email2.addItem("paran.com");
			email2.addItem("hotmail.com");
			email2.addItem("dreamwiz.com");
			email2.addItem("gmail.com");
		}
		return email2;
	}
	private JLabel getLabel_10() {
		if (label_10 == null) {
			label_10 = new JLabel("폰번호");
			label_10.setFont(new Font("굴림", Font.BOLD, 14));
			label_10.setBounds(12, 360, 70, 25);
		}
		return label_10;
	}
	private JLabel getLabel_11() {
		if (label_11 == null) {
			label_11 = new JLabel("강좌명");
			label_11.setFont(new Font("굴림", Font.BOLD, 14));
			label_11.setBounds(12, 395, 70, 25);
		}
		return label_11;
	}
	private JLabel getLabel_12() {
		if (label_12 == null) {
			label_12 = new JLabel("회원 등급");
			label_12.setFont(new Font("굴림", Font.BOLD, 14));
			label_12.setBounds(12, 430, 70, 25);
		}
		return label_12;
	}
	private JComboBox getPhone1() {
		if (phone1 == null) {
			phone1 = new JComboBox();
			phone1.setBounds(88, 360, 57, 22);
			phone1.addItem("010");
			phone1.addItem("011");
			phone1.addItem("015");
			phone1.addItem("016");
			phone1.addItem("017");
			phone1.addItem("018");
			phone1.addItem("019");
		}
		return phone1;
	}
	private JLabel getLabel_13() {
		if (label_13 == null) {
			label_13 = new JLabel("-");
			label_13.setBounds(155, 360, 15, 22);
		}
		return label_13;
	}
	private JTextField getPhone2() {
		if (phone2 == null) {
			phone2 = new JTextField();
			phone2.setColumns(10);
			phone2.setBounds(170, 360, 70, 22);
		}
		return phone2;
	}
	private JLabel getLabel_14() {
		if (label_14 == null) {
			label_14 = new JLabel("-");
			label_14.setBounds(250, 360, 15, 22);
		}
		return label_14;
	}
	private JTextField getPhone3() {
		if (phone3 == null) {
			phone3 = new JTextField();
			phone3.setColumns(10);
			phone3.setBounds(265, 360, 70, 22);
		}
		return phone3;
	}
	private JComboBox getClassname() {
		if (classname == null) {
			classname = new JComboBox();
			classname.addItem("선택");
			classname.setBounds(88, 395, 125, 22);
		}
		return classname;
	}
	private JComboBox getGrade() {
		if (grade == null) {
			grade = new JComboBox();
			grade.setBounds(88, 430, 125, 22);
			grade.addItem("메니져");
			grade.addItem("강사");
			grade.addItem("수강생");
		}
		return grade;
	}
	private JLabel getSajin() {
		if (sajin == null) {
			sajin = new JLabel("");
			sajin.setBorder(new LineBorder(new Color(0, 0, 0)));
			sajin.setBounds(320, 15, 150, 150);
		}
		return sajin;
	}
	private JButton getButton_2() {
		if (button_2 == null) {
			button_2 = new JButton("사진 추가");
			button_2.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					JFileChooser jfc = new JFileChooser();
					int yn = jfc.showOpenDialog(null);
					if(yn==0){
						String filePath = jfc.getSelectedFile().toString();
						fileName = jfc.getSelectedFile().getName();
						if(!fileName.toUpperCase().contains(".PNG") && !fileName.toUpperCase().contains(".JPG")){
							JOptionPane.showMessageDialog(null, "jpg,png 등 이미지 파일만 등록 가능합니다");
							return;
						}
						try {
							FileInputStream fis = new FileInputStream(filePath);
							FileOutputStream fos = new FileOutputStream("mem_img/"+fileName);

							int data=0;
							byte[]  b = new byte[2048];
							while((data=fis.read(b))!=-1){
								fos.write(b, 0, data);
								fos.flush();	
							}

							fis.close();
							fos.close();

							Image img = Toolkit.getDefaultToolkit().getImage("mem_img/"+fileName);
							img = img.getScaledInstance(150, 150, 0);
							ImageIcon icon = new ImageIcon(img);
							sajin.setIcon(icon);

						} catch (Exception e2) {
							e2.printStackTrace();
						}
					}
				}
			});
			button_2.setBounds(225, 125, 85, 35);
		}
		return button_2;
	}
	private JButton getButton_1_1() {
		if (button_1 == null) {
			button_1 = new JButton("수정");
			button_1.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					String m_id = userid.getText().trim();
					if(m_id.equals("")){
						JOptionPane.showMessageDialog(null, "아이디를 입력해주세요!");
						userid.requestFocus();
						return;
					}
					int rs = JOptionPane.showConfirmDialog(null, "정말 수정하시겠습니까?",
							"확인창",JOptionPane.YES_NO_OPTION);
					if(rs==JOptionPane.YES_OPTION){
						String m_name = username.getText().trim();
						String pwd1 = userpwd1.getText().trim();
						String pwd2 = userpwd2.getText().trim();
						String gender="";
						if(radio1.isSelected()==true) gender="여자";
						else if(radio2.isSelected()==true) gender="남자";
						String birth=""; 
						String b_y=(String)birth_year.getItemAt(birth_year.getSelectedIndex());
						String b_m=(String)birth_month.getItemAt(birth_month.getSelectedIndex());
						String b_d=(String)birth_day.getItemAt(birth_day.getSelectedIndex());
						birth = b_y.substring(2, 4)+"/"+b_m.substring(0, 2)+"/"+b_d.substring(0, 2);
						String z_code=zipcode.getText().trim();
						String addr = addr1.getText().trim()+"/"+addr2.getText().trim();
						String email = email1.getText().trim()+"@"+email2.getItemAt(email2.getSelectedIndex());
						String ph1 = (String)phone1.getItemAt(phone1.getSelectedIndex());
						String phone = ph1+"-"+phone2.getText().trim()+"-"+phone3.getText().trim();
						String gra = (String)grade.getItemAt(grade.getSelectedIndex());
						String c_name = (String)classname.getItemAt(classname.getSelectedIndex());

						if(pwd1.equals("")){
							JOptionPane.showMessageDialog(null, "비밀번호를 입력해주세요!");
							userpwd1.requestFocus();
							return;
						}
						if(pwd2.equals("")){
							JOptionPane.showMessageDialog(null, "재확인을 입력해주세요!");
							userpwd2.requestFocus();
							return;
						}
						if(!pwd1.equals(pwd2)){
							JOptionPane.showMessageDialog(null, "비밀번호가 서로 다릅니다!");
							userpwd1.requestFocus();
							return;
						}
						if(m_name.equals("")){
							JOptionPane.showMessageDialog(null, "이름을 입력해주세요!");
							username.requestFocus();
							return;
						}
						if(z_code.equals("")){
							JOptionPane.showMessageDialog(null, "우편번호를 입력해주세요!");
							return;
						}
						if(addr.equals("")){
							JOptionPane.showMessageDialog(null, "주소를 입력해주세요!");
							addr2.requestFocus();
							return;
						}
						if(email1.getText().trim().equals("")){
							JOptionPane.showMessageDialog(null, "이메일을 입력해주세요!");
							email1.requestFocus();
							return;
						}
						if(phone2.getText().trim().length()<3 && phone2.getText().trim().length()>4){
							JOptionPane.showMessageDialog(null, "가운데 자리는 4자리를 입력해주세요!");
							phone2.requestFocus();
							return;
						}
						if(phone3.getText().trim().length()!=4){
							JOptionPane.showMessageDialog(null, "마지막 자리는 4자리를 입력해주세요!");
							phone3.requestFocus();
							return;
						}
						try {
							Integer.parseInt(phone2.getText().trim());
							Integer.parseInt(phone3.getText().trim());
						} catch (Exception e2) {
							JOptionPane.showMessageDialog(null, "핸드폰 번호는 숫자만 입력해주세요!");
							phone2.requestFocus();
							return;
						}
						if(gra.equals("수강생") && c_name.equals("선택")){
							JOptionPane.showMessageDialog(null, "수강생은 클래스명을 선택해주세요!");
							return;
						}
						if(!gra.equals("수강생")) c_name="";

						try {
							String sql="update membertbl set classname=?,m_name=?,m_pwd=?,m_gender=?,m_birth=?,"
									+ "m_zipcode=?,m_addr=?,m_phone=?,m_email=?,m_grade=?,m_photo=? where m_id=?";
							PreparedStatement psmt = con.prepareStatement(sql);
							psmt.setString(1, c_name);
							psmt.setString(2, m_name);
							psmt.setString(3, pwd1);
							psmt.setString(4, gender);
							psmt.setString(5, birth);
							psmt.setString(6, z_code);
							psmt.setString(7, addr);
							psmt.setString(8, phone);
							psmt.setString(9, email);
							psmt.setString(10, gra);
							psmt.setString(11, fileName);
							psmt.setString(12, m_id);

							int cnt = psmt.executeUpdate();
							if(cnt==1){
								JOptionPane.showMessageDialog(null, m_id+"님의 정보가 수정되었습니다");
							}
						} catch (Exception e2) {
							e2.printStackTrace();
						}
					}

				}
			});
			button_1.setFont(new Font("굴림", Font.BOLD, 15));
			button_1.setBounds(250, 456, 100, 30);
		}
		return button_1;
	}
	private JButton getButton_3() {
		if (button_3 == null) {
			button_3 = new JButton("삭제");
			button_3.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					String m_id = userid.getText().trim();
					if(m_id.equals("")){
						JOptionPane.showMessageDialog(null, "아이디를 조회 해주세요!");
						return;
					}
					int rs = JOptionPane.showConfirmDialog(null, "정말 삭제 하시겠습니까?",
							"확인창",JOptionPane.YES_NO_OPTION);
					if(rs==JOptionPane.YES_OPTION){
						try {
							String sql = "delete from membertbl where m_id=?";
							PreparedStatement psmt = con.prepareStatement(sql);
							psmt.setString(1, m_id);
							int cnt = psmt.executeUpdate();
							if(cnt==1){
								JOptionPane.showMessageDialog(null, m_id+"님의 정보가 삭제 되었습니다!");
							}
						} catch (Exception e2) {
							e2.printStackTrace();
						}
						userid.setText("");
						username.setText("");
						userpwd1.setText("");
						userpwd2.setText("");
						radio1.setSelected(true);
						birth_year.setSelectedIndex(0);
						birth_month.setSelectedIndex(0);
						birth_day.setSelectedIndex(0);
						zipcode.setText("");
						addr1.setText("");
						addr2.setText("");
						email1.setText("");
						email2.setSelectedIndex(0);
						phone1.setSelectedIndex(0);
						phone2.setText("");
						phone3.setText("");
						classname.setSelectedIndex(0);
						grade.setSelectedIndex(0);
					}

				}
			});
			button_3.setFont(new Font("굴림", Font.BOLD, 15));
			button_3.setBounds(372, 456, 100, 30);
		}
		return button_3;
	}
	private JButton getButton_4() {
		if (button_4 == null) {
			button_4 = new JButton("조회");
			button_4.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					String m_id="";
					try {
						m_id = JOptionPane.showInputDialog(null, "조회할 아이디를 입력해주세요!");
					} catch (Exception e2) {
						e2.printStackTrace();
					}
					if(m_id!=null && !m_id.equals("")){
						selectMember(m_id);
					}
				}
			});
			button_4.setBounds(223, 10, 85, 25);
		}
		return button_4;
	}
	public void selectMember(String m_id){
		try {
			String sql="select count(*) from membertbl where m_id=?";
			PreparedStatement psmt = con.prepareStatement(sql);
			psmt.setString(1, m_id);
			ResultSet rs = psmt.executeQuery();
			if(rs.next()){
				int cnt = rs.getInt(1);
				if(cnt==0){
					JOptionPane.showMessageDialog(null, m_id+"라는 아이디는 존재하지 않습니다!");
					return;
				}else{
					sql="select m_id,classname,m_name,m_pwd,m_gender,m_birth,m_zipcode,m_addr,"
							+ "m_phone,m_email,m_grade,m_photo from membertbl where m_id=?";
					psmt = con.prepareStatement(sql);
					psmt.setString(1, m_id);
					rs = psmt.executeQuery();
					if(rs.next()){
						userid.setText(rs.getString(1));
						userpwd1.setText(rs.getString(4));
						username.setText(rs.getString(3));
						String gender = rs.getString(5);
						if(gender.equals("여자")) radio1.setSelected(true);
						else if(gender.equals("남자")) radio2.setSelected(true);
						String str = sdf.format(rs.getDate(6));
						String [] birth = str.split("/");
						birth_year.setSelectedItem(birth[0]+"년");
						birth_month.setSelectedItem(birth[1]+"월");
						birth_day.setSelectedItem(birth[2]+"일");
						zipcode.setText(rs.getString(7));
						str = rs.getString(8);
						String [] addr = str.split("/");
						addr1.setText(addr[0]);
						addr2.setText(addr[1]);
						str = rs.getString(9);
						String [] phone = str.split("-");
						phone1.setSelectedItem(phone[0]);
						phone2.setText(phone[1]);
						phone3.setText(phone[2]);
						str = rs.getString(10);
						String [] email = str.split("@");
						email1.setText(email[0]);
						email2.setSelectedItem(email[1]);
						grade.setSelectedItem(rs.getString(11));
						fileName=rs.getString(12);
						Image img = Toolkit.getDefaultToolkit().getImage("mem_img/"+fileName);
						img = img.getScaledInstance(150, 150, 0);
						ImageIcon icon = new ImageIcon(img);
						sajin.setIcon(icon);
						String c_name = rs.getString(2);
						if(c_name==null) classname.setSelectedItem("선택");
						else classname.setSelectedItem(c_name);
					}
				}
			}
		} catch (Exception e2) {
			e2.printStackTrace();
		}
	}
}
